package com.cxzl.pcxt.action.front;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxzl.common.vo.JsonVo;
import com.cxzl.pcxt.entity.User;
import com.cxzl.pcxt.service.UserService;

/**
 * 登录控制器
 * 
 * @author DMJ
 *
 */
@Controller("pcxtLoginAction")
public class LoginAction {

	@Resource(name = "pxctUserService")
	private UserService userService;

	/**
	 * 登录页面
	 * 
	 * @return
	 */
	@RequestMapping("loginPage")
	public String loginPage() {
		return "pcxt/mobile/login";
	}

	/**
	 * 登录
	 */
	@ResponseBody
	@RequestMapping("login.json")
	public JsonVo<User> login(String mobile, String password,
			HttpServletRequest req) {
		JsonVo<User> json = new JsonVo<User>();
		try {
			User user = userService.login(mobile, password);
			req.getSession().setAttribute(User.USER_SESSION_ID, user);
			json.setSuccess(true);
			json.setContent(user);
		} catch (Exception e) {
			json.setMsg(e.getMessage());
			json.setSuccess(false);
		}
		return json;
	}
}
